package com.sxt.springcloud.sys.fallback;

import com.sxt.springcloud.sys.PermissionClientService;
import com.sxt.sys.common.DataGridView;
import com.sxt.sys.common.ResultObj;
import com.sxt.sys.vo.PermissionVo;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@Component
public class PermissionClientFallbackService implements FallbackFactory {
    @Override
    public Object create(Throwable throwable) {
        return new PermissionClientService() {
            @Override
            public List<String> gerPercodeByUserId(Integer userId) {
                List<String> msg = new LinkedList<>();
                msg.add("服务降级，服务器忙，请稍后重试！调用根据percode查询用户方法失败");
                return msg;
            }

            @Override
            public DataGridView loadPermissionManagerLeftTreeJson(PermissionVo permissionVo) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用查询权限管理左侧树方法失败");
            }

            @Override
            public DataGridView loadAllPermission(PermissionVo permissionVo) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用查询所有权限方法失败");
            }

            @Override
            public Map<String, Object> loadPermissionMaxOrderNum() {
                Map<String, Object> map = new HashMap<>();
                map.put("失败方法","服务降级，服务器忙，请稍后重试！调用查询权限的最大值方法失败");
                return map;
            }

            @Override
            public ResultObj addPermission(PermissionVo permissionVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public ResultObj updatePermission(PermissionVo permissionVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public ResultObj deletePermission(PermissionVo permissionVo) {
                return ResultObj.SERVER_BUSY;
            }
        };
    }
}
